package com.example.javatest.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.javatest.entity.domain.InfoSystem;
import com.example.javatest.service.InfoSystemService;
import com.example.javatest.mapper.InfoSystemMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author cac_qin
* @description 针对表【info_system】的数据库操作Service实现
* @createDate 2023-12-12 20:45:03
*/
@Service
public class InfoSystemServiceImpl extends ServiceImpl<InfoSystemMapper, InfoSystem>
    implements InfoSystemService{

    @Resource
    InfoSystemMapper infoSystemMapper;

    @Override
    public boolean create(String infoTitle, String infoText) {
        if(StringUtils.isAnyBlank(infoText,infoTitle)){
            return false;
        }

        InfoSystem infoSystem = new InfoSystem();
        infoSystem.setInfoTitle(infoTitle);
        infoSystem.setInfoText(infoText);
        boolean saveResult = this.save(infoSystem);
        if(!saveResult){
            return false;
        }
        System.out.println(infoSystem);
        return true;
    }

    @Override
    public boolean delete(int id) {
        //查询信息是否存在
        QueryWrapper<InfoSystem> queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("info_Id",id);
        int count = infoSystemMapper.selectCount(queryWrapper);
        if(count<0){
            return false;
        }
        return true;
    }

    @Override
    public List<InfoSystem> listByKey(String searchKey) {
        QueryWrapper<InfoSystem> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("info_Title",searchKey).or().like("info_Text",searchKey);
        return infoSystemMapper.selectList(queryWrapper);
    }
}




